package com.game.spacetrader;

import com.game.spacetrader.TradeGoods.TradeGoodsView;
import com.game.spacetrader.data.DataTest;
import com.game.spacetrader.map.MapView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;

/**
 * Class is the activity for the initial starting screen
 *
 */
public class StartScreen extends Activity implements OnClickListener, OnItemSelectedListener {
	private Button newGame, resumeGame, manageGame, quitGame;
	
	/**
	 * Creates the layout for the start screen
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.startscreen);
		declareButtons();
		//this might be really stupid
	    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
	    StrictMode.setThreadPolicy(policy);
	}
	
	/**
	 * Creates the option menu
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_space_trader, menu);
	    return true;
	}
	 
	/**
	 * Instantiates and creates listeners for the buttons
	 */
	public void declareButtons() {
		newGame = (Button) findViewById(R.id.newGame);
		newGame.setOnClickListener(this);
		
		resumeGame = (Button) findViewById(R.id.resumeGame);
		resumeGame.setOnClickListener(this);
		
		manageGame = (Button) findViewById(R.id.manageGame);
		manageGame.setOnClickListener(this);
		
		quitGame = (Button) findViewById(R.id.quitGame);
		quitGame.setOnClickListener(this);
	}
	
	/**
	 * Listener for when the user clicks on the screen
	 */
	public void onClick(View arg0) {
		switch(arg0.getId()){
		case R.id.newGame:
			Intent gameConfig = new Intent(this, GameConfig.class);
			startActivity(gameConfig);
			break;
		case R.id.resumeGame:
			Intent loadGame = new Intent(this, LoadGame.class);
			startActivity(loadGame);
			break;
		case R.id.manageGame:
			//TODO
			//************************************************************
			//This is Aashish's test code
			Intent dataTest = new Intent(this,DataTest.class);
			startActivity(dataTest);
			break;
			//************************************************************
		case R.id.quitGame:
			//TODO REMOVE THE QUIT BUTTON, UNNECESSARY
			System.exit(0);
			break;
		} 
	}

	/**
     * Listener for the options menu
     * @param item the item in the Menu that is clicked
     */
    @Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case R.id.travel:
	        	Intent i = new Intent(this, MapView.class);
	        	startActivity(i);
	            return true;
	        case R.id.market:
	        	Intent i2 = new Intent(this, TradeGoodsView.class); startActivity(i2);
	        	return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
    
	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
	}

	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		
	}
}
